package com.briup.pts.web.controller;

import com.briup.pts.config.response.Result;
import com.briup.pts.service.UploadService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/file")
@RestController
@RequiredArgsConstructor
public class FileController {

    private final UploadService service;

    // @RequestPart 表示需要接收的是一个以二进制数据流形式传输的文件
    @PostMapping("/upload")
    public Result<String> upload(@RequestPart MultipartFile file){
        String url = service.upload(file);
        return Result.success(url);
    }
}
